import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsEnum, IsOptional, IsString, Length, ValidateIf } from 'class-validator';

export class RoleDto {
  @ApiPropertyOptional({ required: false, description: '角色描述' })
  @IsString({ message: '描述必须是字符串' })
  @Length(1, 255, { message: '名称长度在1-255之间' })
  @ValidateIf((o) => o.description != '')
  @IsOptional()
  description?: string;

  @ApiPropertyOptional({ required: false, description: '默认是否开通' })
  @IsEnum({ 不开通: 0, 开通: 1 }, { message: '平台必须是(1表示开通,0表示不开通)的数字' })
  @Type(() => Number)
  @ValidateIf((o) => o.isDefault != '')
  @IsOptional()
  readonly isDefault?: number;
}
